﻿Imports Awesomium.Core
Imports System.Threading

Module Module1

    Sub Main(args() As String)

        ' Some informative message.
        Console.WriteLine("Getting a 800x600 snapshot of http://www.google.com ...")

        ' We demonstrate an easy way to hide the scrollbars by providing
        ' custom CSS. Read more about how to style the scrollbars here:
        ' http://www.webkit.org/blog/363/styling-scrollbars/.
        ' Just consider that this setting is global. If you want to apply
        ' a similar effect for single pages, you can use ExecuteJavascript
        ' and pass: document.documentElement.style.overflow = 'hidden';
        ' (Unfortunately WebKit's scrollbar does not have a DOM equivalent yet)
        WebCore.Initialize(New WebCoreConfig() With {.CustomCSS = "::-webkit-scrollbar { visibility: hidden; }"})

        ' WebView implements IDisposable. You can dispose and destroy
        ' the view by calling WebView.Close(). Here we demonstrate
        ' wrapping it in a using statement.
        Using webView As WebView = WebCore.CreateWebView(800, 600)
            ' Updated when web-page loading finishes.
            Dim finishedLoading As Boolean

            ' For this sample, navigate to Google.
            webView.LoadURL("http://www.google.com")

            ' Handle LoadComplete.
            AddHandler webView.LoadCompleted,
                Sub(s, e)
                    finishedLoading = True
                End Sub

            Do While Not finishedLoading
                Thread.Sleep(100)
                ' A Console application does not have a synchronization
                ' context, thus auto-update won't be enabled on WebCore.
                ' We need to manually call Update here.
                WebCore.Update()
            Loop

            ' Render to a pixel buffer and save the buffer
            ' to a .png image.
            webView.Render().SaveToPNG("result.png", True)
        End Using

        ' Announce.
        Console.Write("Hit any key to see the result...")
        Console.ReadKey(True)

        ' Start the application associated with .png files
        ' and display the file.
        Process.Start("result.png")

        ' Shut down Awesomium before exiting.
        WebCore.Shutdown()

    End Sub

End Module
